<template>
  <div>
    <el-form
      class="connector-message-content"
      ref="form"
      label-width="80px"
      label-position="left"
      hide-required-asterisk
    >
      <el-form-item :label="$t('common.connector.trigger.notificationType.label')">
        <el-radio-group v-model="type">
          <el-radio label="inside">{{ $t('common.connector.trigger.notificationType.inside') }}</el-radio>
          <el-radio label="customer">{{ $t('common.connector.trigger.notificationType.customer') }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <set-message-content
        ref="setMessageDialogRef"
        :module="module"
        :type="type"
        :messageTypeName="nodeId"
        :value="dialogVisible"
        :key="setMessageDialogKey"
        :biz-type="parentAppBizType"
        :biz-type-id="parentAppBizTypeId"
        :biz-type-ids="parentAppBizTypeIds"
        :node-config="nodeConfig"
      />
    </el-form>
  </div>
</template>
<script>
/* component */
import SetMessageContent from '@src/modules/doMyself/setting/message/components/dialog/SetMessageContent.vue';
/* util */
import { isNotFunction, isEmpty } from '@src/util/type';
import { getToStartNodeFromApiId } from '@src/modules/connector/view/setting/components/workflow/utils/index.js'

export default {
  name: 'message-drawer',
  components: {
    SetMessageContent,
  },
  provide() {
    return {
      // 模块 事件、工单、客户、产品、PaaS
      module: this.module,
      flowData: {},
    };
  },
  props: {
    nodeConfig: {
      type: Object,
      default: () => ({}),
    },

    parent: {
      type: Object,
      default: () => ({}),
    },

  },
  computed: {
    parentApp() {
      
      if (isNotFunction(this.parent?.getParent)) {
        return {}
      }
      
      return this.parent.getParent().isTrigger
        ? this.parent.getParent().getParent().data
        : this.parent.getParent().data;
    },
    parentAppBizType() {
      return this.parentApp?.bizType;
    },
    parentAppBizTypeId() {
      return this.parentApp?.bizTypeId;
    },
    fromBizTypeName() {
      return this.parentApp?.name || '';
    },
    toBizTypeName() {
      return this.app?.data.name || '';
    },
    nodeId() {
      return this.app?.id || '';
    },
    module() {
      return this.parentApp?.bizType?.toLowerCase() || 'api';
    },
    parentAppBizTypeIds () {
      return getToStartNodeFromApiId(this.nodeConfig, [])
    }
  },
  data() {
    return {
      setMessageDialogKey: 0,
      app: this.nodeConfig,
      type: 'inside', // 消息类型 inside：内部，customer：客户
      dialogVisible: true, // 弹框显示/隐藏
      reportSendTime: null, // 日报发送时间
    };
  },
  mounted() {
    // console.log('nodeConfig.data', this.nodeConfig.data);
    const { data } = this.nodeConfig;
    if(!isEmpty(data)) {
      this.type = data.side ? 'customer' : 'inside'
    }
  },
  methods: {
    async getMessageParams() {
      const params = await this.$refs.setMessageDialogRef.saveNeedValidTab()
      params.side = this.type === 'customer' ? 1 : 0
      return params
    },
  },
};
</script>